<template>
	<view class="container">
		<navbar title="课程" color="#333333">
			<view class="left-icon" slot="leftIcon" style="position: absolute;">
				<view class="logo">
					LOGO
				</view>
			</view>
		</navbar>
		<view class="searchBox">
			<headerSearch placeholder="输入关键词进行搜索" bgColor="#F5F5F5" @searchClick="searchClick"></headerSearch>
		</view>
		<view class="content">
			<view class="list_left">
				<view class="item one-row"
				 :class="item.id==category_id ? 'select':''"
				 v-for="(item,i) in classifyList"
				 :key="item.id"
				 @click="selectClassIfy(item)">
					{{item.name}}
				</view>
			</view>
			<view class="list_right">
				<view class="screen">
					<view class="tab">
						<view class="tab-item" :class="tab==1 ? 'select' : ''" @click="tabClick(1)">
							<text>综合</text>
						</view>
						<view class="tab-item" :class="tab==2 ? 'select' : ''" @click="tabClick(2)">
							<text>价格</text>
							<image v-if="sort_price==1" :src="$img_path('/course/sort_1.png')" mode="widthFix"></image>
							<image v-if="sort_price==2" :src="$img_path('/course/sort_2.png')" mode="widthFix"></image>
						</view>
						<view class="tab-item" :class="tab==3 ? 'select' : ''" @click="tabClick(3)">
							<text>销量</text>
							<image v-if="sort_num==1" :src="$img_path('/course/sort_1.png')" mode="widthFix"></image>
							<image v-if="sort_num==2" :src="$img_path('/course/sort_2.png')" mode="widthFix"></image>
						</view>
						<view class="tab-item box-style" @click="tabClick(4,box_style)">
							<image v-if="box_style==1" :src="$img_path('/course/s_i_1.png')" mode="widthFix"></image>
							<image v-if="box_style==2" :src="$img_path('/course/s_i_2.png')" mode="widthFix"></image>
						</view>
					</view>
				</view>
					<scroll-view scroll-y="true" :style="{'--m-h':list_m_h+'px'}" >
				<view class="goodsList">
						<view class="item-box" v-for="(item,i) in c_list" :key="item.id" :style="{width: box_style==2 ? '100%' : 'calc(50% - 7rpx)'}">
							<shopGoods :goodsDetail="item" :styleType="box_style" :imageStyle="box_style==2 ? {width:'232rpx',height:'232rpx'} : null"
							@goodsClick="goodsClick(item)">
								<text slot="center">{{item.play_count}}人订阅</text>
							</shopGoods>
						</view>
						<!-- <view class="style_2" v-for="(item,i) in 10" :key="i">
							<image src="@/static/uni.png" mode="aspectFill"></image>
							<view class="info">
								<view class="name more-row" :style="{'--row-num':2}">
									商品名称商品名称商品名称商
									品名称商品名称商品名称
								</view>
								<view class="price_num">
									<view class="left">
										<view class="price"><text>￥</text>10.00</view>
										<view class="n_price">
											￥10.00
										</view>
									</view>
									<view class="num">
										成交量：100
									</view>
								</view>
							</view>
						</view> -->
				</view>
					</scroll-view>
			</view>
		</view>
		<tarbar index="2" page="2"></tarbar>
	</view>
</template>

<script>
	import {classify, lists} from '@/utils/api/courseApi.js'
	import headerSearch from '../../components/header-search/header-search.vue'
	import shopGoods from '@/components/service-box/goods-box.vue'
	export default {
		components: {
			headerSearch,
			shopGoods
		},
		data() {
			return {
				list_m_h:this.statusBarHeight+this.bottomHeight+this.navBarHeight,
				classifyList:[],
				sort_price: 1,
				sort_num: 1,
				tab:1,
				box_style:1,
				searchValue:'',
				category_id:null,
				c_list:[]
			}
		},
		onLoad() {
			this.getClassift()
		},
		onShow() {
			
		},
		methods:{
			searchClick(){
				uni.navigateTo({
					url:'/pagesCourse/search/search'
				})
			},
			getClassift(){
				classify().then(res=>{
					this.classifyList = res.data
					this.category_id = res.data[0].id
					this.getLists()
				})
			},
			
			goodsClick(data){
				uni.navigateTo({
					url:`/pagesCourse/webview/webview?url=pagesCourse/classify/detail&id=${data.id}`
				})
			},
			
			getLists(){
				let obj={
					category_id:this.category_id,
					q:this.searchValue,
					sort_name:this.tab=='2'?'salesprice':this.tab=='3'?'basic_num':'',
					sort_order:this.tab=='2'?(this.sort_price==1?'DESC':'ASC'):this.tab=='3'?(this.sort_num==1?'DESC':'ASC'):'',
					
				}
				uni.showLoading()
				lists(obj).then(res=>{
					// console.log(res,'---')
					this.c_list = res.data.data
					uni.hideLoading()
				})
			},
			
			selectClassIfy(data){
				this.category_id = data.id
				this.getLists()
			},
			
			tabClick(type,val){
				switch (type){
					case 1:
						break;
					case 2:
						if(this.tab==type){
							if(this.sort_price == 1){
								this.sort_price = 2
							}else{
								this.sort_price = 1
							}
						}
						break;
					case 3:
						if(this.tab==type){
							if(this.sort_num == 1){
								this.sort_num = 2
							}else{
								this.sort_num = 1
							}
						}
						break;
					default:
						if(this.box_style==1){
							this.box_style = 2
						}else{
							this.box_style = 1
						}
						break;
				}
				if(type!=4){
					this.tab = type
				}
				this.getLists()
			},
		}
	}
</script>

<style lang="scss" scoped>
.container{
	
		.left-icon{
			left: 22rpx;
			width: 142rpx;
			height: 68rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0,0,0,0.04);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	
	// padding: 20rpx 30rpx 0;
	box-sizing: border-box;
	.searchBox{
		padding: 20rpx 22rpx 34rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
	}
	.content{
		width: 100%;
		// margin-top: 32rpx;
		display: flex;
		.list_left{
			width: 174rpx;
			height: calc(100vh - 190rpx - var(--m-h));
			overflow-y: auto;
			.item{
				width: 100%;
				height: 74rpx;
				// margin-bottom: 28rpx;
				// background-color: #FFFFFF;
				// border-radius: 10rpx;
				font-weight: bold;
				font-size: 30rpx;
				color: #999999;
				line-height: 74rpx;
				text-align: center;
				&.select{
					background-color: #FFFFFF;
					color: #E72A2A;
				}
			}
		}
		.list_right{
			width: calc(100% - 174rpx);
			padding: 0 22rpx;
			box-sizing: border-box;
			background-color: #FFFFFF;
			.screen {
				// padding: 30rpx 0rpx 0;
				.tab {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 16rpx 24rpx 14rpx;
					// background-color: #FFFFFF;
					border-radius: 10rpx;
					// margin-bottom: 32rpx;
					.tab-item {
						display: flex;
						justify-content: center;
						align-items: center;
						text {
							font-weight: bold;
							font-size: 32rpx;
							color: #999999;
							line-height: 44rpx;
						}
						&.select {
							text {
								color: #E72A2A;
							}
						}
			
						image {
							width: 30rpx;
							height: 30rpx;
						}
					}
				}
			}
			
				scroll-view{
					width: 100%;
					height: calc(100vh - 300rpx - var(--m-h));
				}
			.goodsList{
					display: flex;
					justify-content: space-between;
					flex-wrap: wrap;
				.style_2{
					width: 100%;
					display: flex;
					align-items: center;
					padding: 14rpx 8rpx 12rpx 14rpx;
					box-sizing: border-box;
					background-color: #FFFFFF;
					border-radius: 20rpx;
					margin-bottom: 24rpx;
					&>image{
						width: 192rpx;
						height: 146rpx;
						border-radius: 20rpx;
					}
					.info{
						width: calc(100% - 192rpx);
						padding-left: 8rpx;
						box-sizing: border-box;
						.name{
							font-weight: bold;
							font-size: 26rpx;
							color: #333333;
							line-height: 36rpx;
						}
						.price_num{
							display: flex;
							align-items: flex-end;
							justify-content: space-between;
							margin-top: 22rpx;
							.left{
								display: flex;
								align-items: flex-end;
								.price{
									font-weight: bold;
									font-size: 30rpx;
									color: #FD845C;
									line-height: 40rpx;
									text{
										font-size: 24rpx;
									}
								}
								.n_price{
									font-weight: 400;
									font-size: 20rpx;
									color: #999999;
									line-height: 34rpx;
									text-decoration: line-through;
									margin-top: 6rpx;
									margin-left: 12rpx;
								}
							}
							
							.num{
								font-weight: 400;
								font-size: 16rpx;
								color: #333333;
								line-height: 40rpx;
								margin-top: 6rpx;
							}
						}
					}
				}
			}
		}
	}
}
</style>
